package com.daohang361.imqq.pugin.encoder;

import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.protocol.QQ2011;
import com.daohang361.imqq.tool.ByteArray;
import com.daohang361.imqq.tool.Hex2Bytes;
import com.daohang361.imqq.tool.MyByteSendArray;
import com.daohang361.imqq.tool.MyUtil;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-8 下午10:21:20 
 */
public class Encoder02B4 implements InterfaceEncoder{
	@Override
	public byte[] encode(QQUser myqq, int c) {
		ByteArray myByte = doHead(myqq, "02B4");
//		myByte.putHex("0E 7E 0F 6E");
		myByte.putByte(myqq.getAttr("token_data_2E"));
		myByte.putHex("00 38");
		myByte.putByte(myqq.getAttr("token_data_d1"));
		myByte.saveThis();//保存此段作为第0段
		
			myByte.putHex("00 01");
			myByte.putHex("02 4B");//剩下长度
			myByte.putHex(
					"50 03 C7 4A 28 A2 80 15 7A D3 A9 AB             "+
					"4E A9 60 14 E1 D2 9B 4E 1D 28 E8 01 45 14 AB D6 "+
					"90 0E A2 8A 28 03 9C A7 2F 4A 6D 38 74 AA 66 EC "+
					"5A 28 A2 99 20 3A D3 E9 83 AD 3E 80 0A 55 A4 A7 "+
					"0E 94 09 85 28 EB 49 4E 51 40 74 16 8A 28 A0 90 "+
					"A5 5A 4A 72 F4 A0 05 A7 0E 94 DA 75 02 61 4F A6 "+
					"8E B4 EA 04 2A F5 A7 52 2F 4A 5A 00 29 D4 D1 D6 "+
					"9D 40 05 28 19 A4 A7 2D 00 2D 14 51 40 0E 5E 94 "+
					"B4 83 A5 2D 4B 00 03 34 EA 45 14 B4 30 0A 72 D3 "+
					"69 E3 A5 20 0A 28 A2 80 39 CA 70 E9 4D A7 D5 33 "+
					"66 14 51 45 31 0A BD 69 D4 D5 A7 50 01 4E 1D 29 "+
					"B4 EA 04 C2 9C 3A 53 69 C3 A5 02 62 D1 45 14 08 "+
					"29 C3 A5 36 9F 40 00 EB 4E A6 8E B4 EA 04 C5 1D "+
					"69 D4 8B 4B 4F A8 87 0E 94 B4 83 A5 2D 20 01 D6 "+
					"9D 4D 1D 69 D4 00 53 97 A5 36 9C 3A 50 02 D2 8E "+
					"B4 94 AB 40 0E A2 8A 2A 00 70 E9 45 14 53 60 28 "+
					"19 34 EA 6A F5 A7 52 00 A2 8A 28 03 9C A7 D3 40 "+
					"CD 3A AC D9 85 14 51 40 87 2F 4A 5A 41 D2 96 80 "+
					"01 D6 9D 4D 1D 69 D4 0B A8 53 87 4A 6D 38 74 A0 "+
					"18 B4 51 45 04 80 EB 4F A6 8E B4 EA 00 55 A5 A4 "+
					"5E 94 B4 13 D4 70 18 A5 A2 8A 00 70 E9 4B 45 14 "+
					"00 0E B4 EA 45 E9 4B 40 05 3E 9A 3A D3 A8 00 A7 "+
					"2F 4A 6D 38 74 A0 05 A5 5E B4 94 AB D2 A0 05 A2 "+
					"8A 50 33 4D 80 A0 62 96 8A 29 00 51 45 14 01 CF "+
					"2F 4A 5A 41 D2 96 9F 53 66 14 51 4A 3A D5 08 75 "+
					"14 51 40 0A BD 69 69 17 AD 2D 04 05 3C 74 A6 53 "+
					"E8 1B 0A 28 A0 75 A0 42 AD 3A 90 0C 0A 51 D6 80 "+
					"1C 3A 52 8E B4 94 AB D6 82 47 52 8E B4 94 AB D6 "+
					"80 1D 45 14 50 03 87 14 51 45 00 2A F5 A7 52 2D "+
					"2D 00 14 FA 68 19 A7 52 60 14 E1 D2 9B 4E A4 80 "+
					"29 57 AD 25 39 69 00 B4 51 45 00 14 51 45 00 73 "+
					"E3 A5 14 51 4D 1A 85 2A F5 A2 8A A0 1D 45 14 50 "+
					"02 AD 2D 14 50 24 28 EB 4E A2 8A 04 C2 94 75 A2 "+
					"8A 04 3A 81 D6 8A 28 01 D4 E1 D2 8A 28 24 5A 72 "+
					"F4 A2 8A 00 5A 28 A2 80 1D 45 14 50 03 97 A5 2D "+
					"14 50 03 87 4A 5A 28 A4 C0 07 5A 75 14 50 80 29 "+
					"CB 45 15 20 2D 14 51 40 05 14 51 40 1F FF D9    ");
			
		myByte.saveThis();//保存此段作为第一段
		System.out.println("imgKey:"+Hex2Bytes.bytesToHexString(myqq.getAttr("imgKey")));
		myByte.teaThis(1, 1,myqq.getAttr("imgKey"));//加密第一段到第一段
		doTail(myByte);
		return myByte.getByteList();//返回完整的package
	}
	
	private boolean ignore=false;
	@Override
	public byte[] encode(QQUser myqq, int c,Object...o) {
		System.out.println("使用默认编码器 命令为:"+MyUtil.intTo2Hex(c));
		ByteArray array=doHead(myqq,MyUtil.intTo2Hex(c));
		array.saveThis();//保存此段作为第0段
		array.putByte(myqq.getSend());
		array.saveThis();//保存此段作为第一段
		array.teaThis(1, 1,myqq.getAttr("SessionKey"));//加密第一段到第一段
		array=doTail(array);
		return array.getByteList();
	}

	public ByteArray doHead(QQUser myqq,String HexCommand)
	{
		ByteArray myByte = new MyByteSendArray();
		myByte.putHex("05");//05系列
		myByte.putInt(QQ2011.QQ_PROTOCOL_VERSION);
		myByte.putHex(HexCommand);
		myByte.putHex("00 33");
		myByte.putInt(myqq.getPakage());
		myByte.putInt(myqq.getQq());
		myByte.putHex("01 00 00 00 00 00 00 00");
		return myByte;
	}
	public ByteArray doTail(ByteArray myByte)
	{
		myByte.putInt(QQ2011.QQ_PROTOCOL_PACKAGE_TAIL);
		myByte.saveThis();//保存此段作为第二段
		return myByte;//返回完整的package
	}
	
	@Override
	public boolean getIgnore() {
		
		return ignore;
	}
	
	@Override
	public void setIgnore(boolean ignore) {
		this.ignore=ignore;
	}
	@Override
	public Object invoke(Object... o) {
	return null;
	}
}
